import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';

class InfoDetail extends StatelessWidget{

  int id;
  String title;
  InfoDetail({this.id,this.title});

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Info(id:id,title: title,);
  }


}

// ignore: must_be_immutable
class Info extends StatefulWidget{

  int id;
  String title;
  Info({this.id,this.title});

  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return InfoWidget(id:id,title: title);
  }

}

class InfoWidget extends State<Info>{

  String url="https://guangdiu.com/api/showdetail.php";
  GlobalKey<ScaffoldState> globalKey=new GlobalKey();
  String loadUrl;
  String currentUrl;
  List<String> urls=[];

  int id;
  String title;

  InfoWidget({this.id,this.title});
  FlutterWebviewPlugin flutterWebviewPlugin=FlutterWebviewPlugin();
  StreamSubscription<String> _urlchange;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _urlchange=flutterWebviewPlugin.onUrlChanged.listen((url){
      currentUrl=url;
      print("----------  $currentUrl");
    });

    flutterWebviewPlugin.onStateChanged.listen((state){
      if(state.type==WebViewState.finishLoad){

      }
    });

    flutterWebviewPlugin.onHttpError.listen((error){
      print("vvvvvvvvvvvv   ${error.code}");
    });



  }


  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    loadUrl="$url?id=$id&btn=1&kepler=1&bc=1";
    print(loadUrl);
    return WebviewScaffold(
      key: globalKey,
      appBar: AppBar(
        title: Text(title),
        leading: IconButton(
            icon: Icon(Icons.arrow_back,color: Colors.white,),
            onPressed: (){
              Navigator.pop(context);
            }),
      ),
      url: loadUrl,
      withZoom: false,
      withLocalUrl: true,
      withLocalStorage: true,
      withJavascript: true,
      enableAppScheme: false,
      clearCache: true,

    );
  }

}